#ifndef __LOGREG_H__
#define __LOGREG_H__

#include <iostream>
#include "FileTools.h"
#include "StdMyString.h"
#include <openssl/sha.h>
#include "Interface.h"
#include "Global.h"
#include "Monster.h"
#include "Player.h"
#include "Scene.h"
#include <ctime>

// 生成随机盐值
std::string Generate();
// 哈希加盐
std::pair<std::string, std::string> HashWithSalt(const std::string &passwd);
// 判断密码是否相等
bool IsPasswdSame(const std::string &passwd, const std::string &salt, const std::string &Hash);

// 登录
void Login();
// 注册
void Register();

// 抽象虚基类
class Abstract
{
public:
    virtual void run() = 0;
};

// 登录实现
class LoginRealize : public Abstract
{
public:
    void run() override
    {
        Login();
    }
};

// 注册实现
class RegisterRealize : public Abstract
{
public:
    void run() override
    {
        Register();
        Login();
    }
};

// 代理类
class Proxy
{
public:
    void Run(int function)
    {
        if (function == 0)
        {
            s = new LoginRealize;
            s->run();
        }

        if (function == 1)
        {
            s = new RegisterRealize;
            s->run();
        }
    }

private:
    Abstract *s;
};

#endif